﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace XnaAux
{


    /// <summary>
    /// Class that contains animation clips data. THis class is 
    /// shared between content processing and the runtime.
    /// </summary>
    public class AnimationClips
    {
        public interface Bone
        {
            bool Valid { get; }
            Quaternion Rotation { get; }
            Vector3 Translation { get; }
        }

        /// <summary>
        /// A Keyframe is a rotation and translation for a moment in time.
        /// </summary>
        public class Keyframe
        {
            #region Member Variables
            private double mTime;        // The keyframe time
            private Quaternion mRotation; // The rotation for the bone
            private Vector3 mTranslation; // The translation of the bone
            #endregion

            #region Properties
            /// <summary>
            /// The keyframe time
            /// </summary>
            public double Time { get { return mTime; } set { mTime = value; } }

            /// <summary>
            /// The rotation for the bone
            /// </summary>
            public Quaternion Rotation { get { return mRotation; } set { mRotation = value; } }

            /// <summary>
            /// The translation of the bone
            /// </summary>
            public Vector3 Translation { get { return mTranslation; } set { mTranslation = value; } }

            #endregion
        }

        /// <summary>
        /// An animation clip is a set of keyframes.
        /// </summary>
        public class Clip
        {
            #region Member Variables

            /// <summary>
            /// Name of the animation clip.
            /// </summary>
            private string mName;

            /// <summary>
            /// Duration of the animation clip.
            /// </summary>
            private double mDuration;

            /// <summary>
            /// The keyframes in the animation. We have an array of bones
            /// each with a list of keyframes
            /// </summary>
            private List<Keyframe>[] mKeyframes;

            /// <summary>
            /// Whether or not we are looping
            /// </summary>
            private bool mLooping = false;
            /// <summary>
            /// The speed of the keyframe
            /// </summary>
            private double mSpeed = 1.0f;
            
            /// <summary>
            /// Time it takes for the keyframe to elapse
            /// </summary>
            private double mTime;

            

            private int mBoneCnt;


            #endregion

            #region Properties

            /// <summary>
            /// Indicates if the playback should "loop" or not
            /// </summary>
            public bool Looping { get { return mLooping; } set { mLooping = value; } }

            /// <summary>
            /// Playback Speed
            /// </summary>
            public double Speed { get { return mSpeed; } set { mSpeed = value; } }

            /// <summary>
            /// Name of the animation clip.
            /// </summary>
            public string Name { get { return mName; } set { mName = value; } }

            /// <summary>
            /// Duration of the animation clip.
            /// </summary>
            public double Duration { get { return mDuration; } set { mDuration = value; } }

            /// <summary>
            /// The keyframes in the animation. We have an array of bones
            /// each with a list of keyframes
            /// </summary>
            public List<Keyframe>[] Keyframes { get { return mKeyframes; } set { mKeyframes = value; } }

            public int BoneCount { get { return mBoneCnt; } set { mBoneCnt = value; } }

            public double Time { get { return mTime; } set { mTime = value; } }
            
            #endregion

        }

        public Dictionary<string, Clip> Clips = new Dictionary<string, Clip>();

        public List<int> SkelToBone { get; set; }
    }
}
